# Copyright (C) Kumo inc. and its affiliates.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https:#www.gnu.org/licenses/>.
#
# Build the test and build container for presto_cpp
#
FROM ghcr.io/facebookincubator/pollux-dev:centos9

ARG SPARK_VERSION=3.5.1

ADD scripts /pollux/scripts/
RUN wget https://archive.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop3.tgz
RUN wget https://repo1.maven.org/maven2/org/apache/spark/spark-connect_2.12/${SPARK_VERSION}/spark-connect_2.12-${SPARK_VERSION}.jar

ARG SPARK_PKG=spark-${SPARK_VERSION}-bin-hadoop3.tgz
ARG SPARK_CONNECT_JAR=spark-connect_2.12-${SPARK_VERSION}.jar

ENV SPARK_HOME="/opt/spark-server"

RUN dnf install -y java-11-openjdk less procps python3 tzdata \
    && ln -s $(which python3) /usr/bin/python \
    && tar -zxf $SPARK_PKG \
    && mv ./spark-${SPARK_VERSION}-bin-hadoop3 $SPARK_HOME \
    && mkdir ${SPARK_HOME}/misc/ \
    && mv ./$SPARK_CONNECT_JAR ${SPARK_HOME}/misc/

# We set the timezone to America/Los_Angeles due to issue
# detailed here : https://github.com/facebookincubator/pollux/issues/8127
ENV TZ=America/Los_Angeles

COPY scripts/spark/conf/spark-defaults.conf.example $SPARK_HOME/conf/spark-defaults.conf
COPY scripts/spark/conf/spark-env.sh.example $SPARK_HOME/conf/spark-env.sh
COPY scripts/spark/conf/workers.example $SPARK_HOME/conf/workers
COPY scripts/spark/start-spark.sh /opt

WORKDIR /pollux
